package org.iabako.client.ui.form.extranet.signup;

import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.HTMLPanel;
import org.iabako.client.config.page.PageConfigEnum;
import org.iabako.client.tools.Messages;
import org.iabako.client.ui.form.AbstractForm;
import org.iabako.client.ui.layout.field.IField;
import org.iabako.client.ui.layout.field.LabelText;
import org.iabako.shared.entity.business.AbstractEntity;
import org.iabako.shared.entity.enumeration.IabakoPackage;
import org.iabako.shared.entity.enumeration.SignUpStep;
import org.iabako.shared.entity.user.Enterprise;
import org.iabako.shared.entity.user.User;

import java.util.List;

/**
 * Created by jose on 05/12/14.
 */
public class SignUpForm extends AbstractForm {

    interface MyUiBinder extends UiBinder<HTMLPanel, SignUpForm> {
    }

    protected MyUiBinder binderForm = GWT.create(MyUiBinder.class);

    @UiField
    LabelText signUpPlan;
    @UiField
    SignUpEnterpriseForm signUpEnterpriseForm;
    @UiField
    SignUpUserForm signUpUserForm;
    @UiField
    SignUpEmailValidationForm signUpEmailValidationForm;
    @UiField
    SignUpDoneForm signUpDoneForm;
    @UiField
    LabelText signUpTitle;
    @UiField
    SignUpPaymentForm signUpPaymentForm;

    Enterprise enterprise;
    User user;
    String plainPassword;

    IabakoPackage signUpIabakoPackage;

    public SignUpForm() {
        simplePopup = true;
        setForm(binderForm, PageConfigEnum.SignUp, null);

        signUpEnterpriseForm.setSignUpForm(this);
        signUpUserForm.setSignUpForm(this);
        signUpEmailValidationForm.setSignUpForm(this);
        signUpPaymentForm.setSignUpForm(this);
        signUpDoneForm.setSignUpForm(this);
    }

    protected void setPackage(IabakoPackage signUpIabakoPackage) {
        this.signUpIabakoPackage = signUpIabakoPackage;

        signUpPlan.setHtmlLabel(Messages.getLabel("sign_up_plan", signUpIabakoPackage.getLabel()));
        if (!signUpIabakoPackage.isFree()) {
            signUpTitle.setLabel("sign_up_title_4_steps");
        }

        goTo(SignUpStep.signUpEnterprise);
    }

    public IabakoPackage getSignUpIabakoPackage() {
        return signUpIabakoPackage;
    }

    public Enterprise getEnterprise() {
        return enterprise;
    }

    public void setEnterprise(Enterprise enterprise) {
        this.enterprise = enterprise;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public void goTo(SignUpStep signUpStep) {

        signUpEnterpriseForm.setVisible(false);
        signUpUserForm.setVisible(false);
        signUpEmailValidationForm.setVisible(false);
        signUpPaymentForm.setVisible(false);
        signUpDoneForm.setVisible(false);

        switch (signUpStep) {
            case signUpEnterprise:
                signUpEnterpriseForm.setVisible(true);
                break;
            case signUpUser:
                signUpUserForm.setVisible(true);
                break;
            case signUpEmailValidation:
                signUpEmailValidationForm.setVisible(true);
                break;
            case signUpPayment:
                signUpPaymentForm.setVisible(true);
                break;
            case signUpDone:
                signUpTitle.setVisible(false);
                signUpPlan.setVisible(false);
                messages.setVisible(false);
                signUpDoneForm.setVisible(true);
                break;
        }
    }

    public void setPlainPassword(String plainPassword) {
        this.plainPassword = plainPassword;
    }

    public String getPlainPassword() {
        return plainPassword;
    }

    @Override
    protected List<IField> getMandatoryFields() {
        return null;
    }

    @Override
    protected AbstractEntity getEntity() {
        return null;
    }

    @Override
    public boolean validate() {
        return false;
    }
}
